package com.baizhi.controller;

import com.baizhi.entity.Menu;
import com.baizhi.service.MenuService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @RequestMapping("/showAllMenu")
    public @ResponseBody List<Menu> showAllMenu(){
//        假设菜单管理必须是超级管理员才能查询
//                代码式授权
        Subject subject = SecurityUtils.getSubject();
        if(subject.hasRole("superadmin")){
            List<Menu> menus = menuService.selecyAll();
            return menus;
        }else{
            return null;
        }

    }
}
